<!-- +----------------------------------------------------------------------
| 麦沃德科技赋能开发者，助力中小企业发展 
+----------------------------------------------------------------------
| Copyright (c) 2017～2024  www.wdadmin.cn    All rights reserved.
+----------------------------------------------------------------------
| 沃德代驾系统并不是自由软件，不加密，并不代表开源，未经许可不可自由转售和商用
+----------------------------------------------------------------------
| Author: MY WORLD Team <bd@maiwd.cn>   www.wdadmin.cn
+----------------------------------------------------------------------
| 安全中心 开发者: 麦沃德科技-半夏  
+---------------------------------------------------------------------- -->

<template>
	<view class="container" v-if="loadEnd">
		<!-- 标题栏 -->
		<title-bar title="安全中心" :showBack="true" :backgroundColor="titleBackground" :frontColor="titleColor"></title-bar>
		<!-- 顶部背景 -->
		<view class="container-background">
			<image class="background-image" src="/static/security_bg.png" mode="widthFix"></image>
			<image class="background-icon" src="/static/security_icon.png" mode="aspectFit"></image>
		</view>
		<!-- 页面内容 -->
		<view class="container-main">
			<view class="main-header">
				<view class="header-title">安全中心</view>
				<view class="header-subtitle">全面保障您的出行安全</view>
			</view>
			<view class="main-tool">
				<view class="tool-title">安全工具</view>
				<view class="tool-list flex justify-content-between flex-wrap">
					<view class="list-item flex align-items-center" @click="toAuthentication()">
						<view class="item-bg"></view>
						<view class="item-icon" :style="{'background-image': 'url('+ toolIcon +')'}" v-if="toolIcon"></view>
						<view class="item-info">
							<view class="info-title">实名认证</view>
							<view class="info-status active" v-if="securityInfo.certification_status == 1">已认证</view>
							<view class="info-status" v-else>未认证</view>
						</view>
					</view>
					<!-- <view class="list-item flex align-items-center" @click="toPrivacyPhone()" v-if="securityInfo.privacy_number_status == 1">
						<view class="item-bg"></view>
						<view class="item-icon" :style="{'background-image': 'url('+ toolIcon +')'}" v-if="toolIcon"></view>
						<view class="item-info">
							<view class="info-title">隐私号码保护</view>
							<view class="info-subtitle">保护司乘隐私</view>
						</view>
					</view> -->
					<view class="list-item flex align-items-center" @click="toTravelRecording()" v-if="securityInfo.sound_recording_status == 1">
						<view class="item-bg"></view>
						<view class="item-icon" :style="{'background-image': 'url('+ toolIcon +')'}" v-if="toolIcon"></view>
						<view class="item-info">
							<view class="info-title">行程录音</view>
							<view class="info-status active">已开启</view>
						</view>
					</view>
				</view>
			</view>
			<view class="main-footer">
				<view class="footer-btn" @click="toAlarm()">110报警</view>
				<view class="safe-padding"></view>
			</view>
		</view>
	</view>
</template>

<script>
	import { mapState } from "vuex"
	import svgData from "@/common/svg.js"
	import titleBar from "@/pages/component/title-bar/title-bar.vue"
	export default {
		components: {
			titleBar,
		},
		data() {
			return {
				// 加载完成
				loadEnd: false,
				// 标题栏背景颜色
				titleBackground: "transparent",
				// 标题栏字体颜色
				titleColor: "white",
				// 安全中心数据
				securityInfo: {},
			}
		},
		computed: {
			...mapState({
				shareTitle: state => state.app.shareTitle,
				shareImage: state => state.app.shareImage,
			}),
			toolIcon: () => {
				return svgData.svgToUrl("security_tool", "#0077FF")
			},
		},
		onLoad() {
			uni.setNavigationBarColor({
				frontColor: "#ffffff", //文字颜色
				backgroundColor: "transparent" //底部背景色
			})
			uni.showLoading({
				title: "加载中"
			})
			this.getSecurityInfo(() => {
				uni.hideLoading()
				this.loadEnd = true
			})
		},
		onShow() {
			if (this.loadEnd) {
				this.getSecurityInfo()
			}
		},
		onPageScroll(e) {
			const scrollTop = e.scrollTop
			if (scrollTop > 100) {
				this.titleBackground = "#fff"
				this.titleColor = "black"
			} else {
				let opacity = parseFloat(scrollTop / 100).toFixed(4)
				this.titleBackground = "rgba(255, 255, 255, " + opacity + ")"
				if (scrollTop > 30) {
					this.titleColor = "black"
					uni.setNavigationBarColor({
						frontColor: "#000000", //文字颜色
						backgroundColor: "#ffffff" //底部背景色
					})
				} else {
					this.titleColor = "white"
					uni.setNavigationBarColor({
						frontColor: "#ffffff", //文字颜色
						backgroundColor: "transparent" //底部背景色
					})
				}
			}
		},
		onShareAppMessage() {
			return {
				title: this.shareTitle,
				imageUrl: this.shareImage,
			}
		},
		onShareTimeline() {
			return {
				title: this.shareTitle,
				imageUrl: this.shareImage,
			}
		},
		methods: {
			// 获取安全中心信息
			getSecurityInfo(fn) {
				this.$util.request("driver.security").then(res => {
					if (fn) fn()
					if (res.code == 1) {
						this.securityInfo = res.data
					} else {
						uni.showToast({
							title: res.msg,
							icon: 'none'
						})
					}
				}).catch(error => {
					if (fn) fn()
					console.error('获取安全中心信息 ', error)
				})
			},
			// 跳转实名认证
			toAuthentication() {
				this.$util.toPage({
					mode: 1,
					path: "/pages/driver/mine/authentication/index",
					isToken: true,
				})
			},
			// 跳转隐私号码保护
			toPrivacyPhone() {
				this.$util.toPage({
					mode: 1,
					path: "/pages/driver/mine/security/privacyPhone",
				})
			},
			// 跳转行程录音
			toTravelRecording() {
				this.$util.toPage({
					mode: 1,
					path: "/pages/driver/mine/security/travelRecording",
				})
			},
			// 跳转110报警
			toAlarm() {
				this.$util.toPage({
					mode: 1,
					path: "/pages/driver/mine/security/alarm",
					isToken: true,
				})
			},
		}
	}
</script>

<style lang="scss">
	.container {
		position: relative;
		padding-bottom: 112rpx;

		.container-background {
			position: absolute;
			top: 0;
			left: 0;
			right: 0;

			.background-image {
				width: 100%;
				height: 100%;
			}

			.background-icon {
				position: absolute;
				top: 50%;
				right: 48rpx;
				transform: translateY(-45%);
				width: 240rpx;
				height: 260rpx;
			}
		}

		.container-main {
			position: relative;
			z-index: 1;
			padding: 0 32rpx 32rpx;

			.main-header {
				padding-top: 68rpx;

				.header-title {
					color: #FFF;
					font-size: 48rpx;
					font-weight: 600;
					line-height: 68rpx;
				}

				.header-subtitle {
					margin-top: 16rpx;
					color: #FFF;
					font-size: 28rpx;
					font-weight: 600;
					line-height: 40rpx;
				}
			}

			.main-tool {
				margin-top: 124rpx;
				border-radius: 32rpx;
				background: #FFF;
				padding: 32rpx 32rpx 48rpx;

				.tool-title {
					color: #242629;
					font-size: 28rpx;
					font-weight: 600;
					line-height: 40rpx;
				}

				.tool-list {
					.list-item {
						padding: 28rpx 20rpx;
						width: calc(50% - 16rpx);
						margin-top: 32rpx;
						border-radius: 16rpx;
						background: #F2F8FF;

						.item-icon {
							width: 64rpx;
							height: 64rpx;
							background-size: 64rpx;
						}

						.item-info {
							margin-left: 16rpx;

							.info-title {
								color: #242629;
								font-size: 28rpx;
								font-weight: 600;
								line-height: 40rpx;
							}

							.info-status {
								margin-top: 8rpx;
								color: #F9602E;
								font-size: 24rpx;
								font-weight: 600;
								line-height: 34rpx;

								&.active {
									color: #0077FF;
								}
							}

							.info-subtitle {
								color: #8D929C;
								font-size: 24rpx;
								font-weight: 600;
								line-height: 34rpx;
							}
						}
					}
				}
			}

			.main-footer {
				position: fixed;
				left: 0;
				right: 0;
				bottom: 0;
				z-index: 99;
				padding: 16rpx 24rpx;
				background: #ffffff;
				border-top: 1rpx solid #F6F7FB;

				.footer-btn {
					color: #FFF;
					text-align: center;
					font-size: 28rpx;
					font-weight: 600;
					line-height: 40rpx;
					padding: 20rpx 24rpx;
					border-radius: 40rpx;
					background: #DE2828;
				}
			}
		}
	}
</style>